#ifndef LINKS_EDITOR_DIALOG_H
#define LINKS_EDITOR_DIALOG_H

#include <QtGui/QDialog>

namespace core
{
class IDocument;
}

QT_BEGIN_NAMESPACE
class QItemSelection;
class QListView;
class QStandardItemModel;
QT_END_NAMESPACE

namespace gui
{

class LinksEditorDialog : public QDialog
{
    Q_OBJECT

public:
    LinksEditorDialog(
        const QList<QSharedPointer<core::IDocument> >& canBeAdded,
        const QList<QSharedPointer<core::IDocument> >& canBeRemoved,
        QWidget* parent, bool singleLinkMode = false);
    ~LinksEditorDialog();

    QList<QSharedPointer<core::IDocument> > added() const;
    QList<QSharedPointer<core::IDocument> > removed() const;

private:
    void initModels();
    void createLayout();
    void connectSlots();
    void ensureSelected();

public slots:
    void accept();

private slots:
    void addSelected();
    void removeSelected();

    void checkButtons();

    void checkAdd(const QItemSelection& selected,
        const QItemSelection& deselected);
    void checkRemove(const QItemSelection& selected,
        const QItemSelection& deselected);

private:
    bool m_singleLinkMode;

    QPushButton* m_okButton;
    QPushButton* m_cancelButton;

    QPushButton* m_addButton;
    QPushButton* m_removeButton;

    QListView* m_canBeAddedView;
    QListView* m_canBeRemovedView;

    QStandardItemModel* m_canBeAddedModel;
    QStandardItemModel* m_canBeRemovedModel;

    QList<QSharedPointer<core::IDocument> > m_added;
    QList<QSharedPointer<core::IDocument> > m_removed;

    QList<QSharedPointer<core::IDocument> > m_canBeAdded;
    QList<QSharedPointer<core::IDocument> > m_canBeRemoved;
};

} // namespace gui

#endif
